package kr.ac.kaist.idb.csnql.clause;

import java.io.Serializable;
import java.util.*;

/**
 * 
 * @brief CASE clause
 * @author Jongheon Park (korex527@kaist.ac.kr)
 *
 */
public class SNQLCase implements Serializable{

	/**
	 * @brief Serial version UID which is automatically generated
	 */
	private static final long serialVersionUID = 7641332003320108221L;
	/**
	 * @brief List of SNQLWhenExp : WHEN clause
	 */
	private Vector<SNQLWhenExp> iCase; 
	
	/**
	 * @brief Instantiates a new SNQLCase.
	 */
	public SNQLCase()
	{
		iCase = new Vector<SNQLWhenExp>();
	}
	
	/**
	 * @brief Instantiates a new SNQLCase with WHEN clause List.
	 *
	 * @param vector WHEN clause List
	 */
	public SNQLCase(Vector<SNQLWhenExp> vector)
	{
		iCase = vector;
	}
	
	/**
	 * @brief Adds the WHEN clause
	 *
	 * @param iWhenExp WHEN clause
	 */
	public void addWhenExp(SNQLWhenExp iWhenExp)
	{
		iCase.add(iWhenExp);
	}
	
	/**
	 * @param index The index
	 * @return WHEN clause
	 * @brief Get the WHEN clause
	 */
	public SNQLWhenExp getWhenExp(int index)
	{
		if (index < iCase.size())
			return (SNQLWhenExp)iCase.get(index);
		else
			return null;
	}
	
	/**
	 * @return CASE clause
	 * @brief Get the CASE clause
	 */
	public Vector<SNQLWhenExp> getiCase() {
		return iCase;
	}

	/**
	 * @param iCase New CASE clause
	 * @brief Set the CASE clause
	 */
	public void setiCase(Vector<SNQLWhenExp> iCase) {
		this.iCase = iCase;
	}
	
	public String toString()
	{
		StringBuffer stringbuffer = new StringBuffer();
		stringbuffer.append("\nCASE \n");
		
		Enumeration<SNQLWhenExp> en = iCase.elements();
		
		while(en.hasMoreElements())
		{
			SNQLWhenExp wExp = (SNQLWhenExp) en.nextElement();
			
			stringbuffer.append(wExp.toString() + "\n");
		}
		//@todo
		return stringbuffer.toString();
	}
}
